package src;

import java.util.Scanner;
    public class Book_Library
    {
        //2.设计图书管理系统，实现以下功能
        int capacity=5;
        int num1=0;
        int num2=0;
        double[] price= new double[capacity];
        String[] name = new String[capacity];
        int [] number = new int[capacity];
        double sum=0;
        double average=0;
        double max,min;
        Scanner scanner = new Scanner(System.in);
        void message_() //输入5本书的书号，书本以及价格
        {
            for (int i = 0; i < price.length; i++) {
                int m = i + 1;
                System.out.print("请输入第" + m + "书的书名  ");
                Scanner a = new Scanner(System.in);
                name[i] = a.nextLine();
                System.out.print("请输入第" + m + "书的书号  ");
                Scanner b = new Scanner(System.in);
                number[i] = b.nextInt();
                System.out.print("请输入第" + m + "书的价格  ");
                price[i] = scanner.nextDouble();
                System.out.println();
            }

        }
        void show()//输出
        {
            {
                for (int n = 0; n < number.length; n++)
                {
                    int y = n + 1;
                    System.out.println("第" + y + "本书的书号为" + name[n]);
                    System.out.println("第" + y + "本书的书名为" + number[n]);
                    System.out.println("第" + y + "本书的价格为" + price[n]);
                }
            }
        }
        void   count(double  price [],String name[],int number[])
        {//计算书的总价以及平均价格，显示最高价格，最低价格，按价格降序排列，高于平均价格和低于平均价格的数量

            for( int j=0;j<price.length;j++)
            {
                double a = 0;
                for (int m = 0; m < price.length - j - 1; m++)
                {
                    if (price[m] < price[m + 1]) {
                        a = price[m + 1];
                        price[m + 1] = price[m];
                        price[m] = a;
                    }
                }
                sum = price[j] + sum;
                System.out.println("书的价格"+price[j]+"\t\t书的名字为"+name[j]+"\t\t书的书号为"+number[j]);
            }
            min=price[price.length-1];
            max=price[0];
            average=sum/(price.length);
            System.out.println();
            System.out.println("书的最低价格"+min+"\t书的最高价格"+max);
            System.out.println();
            System.out.println("书的总价"+sum+"\t\t书的平均价格"+average);
            System.out.println();
            for(int n=0;n<price.length;n++)
            {
                if(price[n]<=average)
                    num1++;
                else
                    num2++;
            }
            System.out.println("低于平均价的书有"+num1+"本");
            System.out.println("高于平均价的书有"+num2+"本");
        }
        void select(int number[],double price[],String name[])
        {//输入书号查询书的价格以及书名
            int m=0;
            System.out.println("请输入你想查询的书号");
            int  l=scanner.nextInt();
            while( m<number.length)
            {
                if (l == number[m])
                {
                    System.out.println("此书的价格为:" + price[m]);
                    System.out.println("此书的书名为:" + name[m]);
                    break;
                }
                m++;
            }
            if(m==number.length)
            {
                System.out.println("查无此书");
            }
        }
        public static void main(String[] args)

        {Book_Library a1=new Book_Library();
            a1.message_();
            a1.count(a1.price, a1.name, a1.number);
            a1.select(a1.number, a1.price, a1.name);
        }
    }




